package com.jie.boot.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jie.boot.domain.User;
import com.jie.boot.service.TaskService;
import com.jie.boot.service.UserService;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private TaskService taskService;

    @GetMapping(value = "list")
    public String list(Model model) {
        List<User> users = userService.findWithTask("张三", "操作傀儡");
        model.addAttribute("users", users);
        return "users";
    }

    @PostMapping(value = "add")
    public String add(User user) {
        userService.save(user);
        return "redirect:/user/list";
    }
}
